package client;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ImagePanel extends JPanel{
    private static final long serialVersionUID = 1L;

    private BufferedImage background;
    private BufferedImage background2;
    
    Client client;
    
    public ImagePanel(Client client){
        this.client = client;

        // Load backgrounds
        try {
            background = ImageIO.read(new File("backgroundXP.png"));
            background2 = ImageIO.read(new File("backgroundXP2.png"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        // Setup
        this.setBackground(new Color(0, 0, 0, 0));
        this.setPreferredSize(new Dimension(background.getWidth(), background.getHeight()));
        
        // Really not a good thing to do, but whatever.
        client.width = background.getWidth();
        client.height = background.getHeight();
    }
    
    @Override
    public void paintComponent(Graphics g){
        switch(client.state) {
        case LOGIN:
            g.drawImage(background, 0, 0, null);
            break;
        case CONNECTED:
            g.drawImage(background2, 0, 0, null);
            break;
        case LOCKED:
            g.drawImage(background2, 0, 0, null);
            g.setColor(new Color(0f, 0f, 0f, 0.5f));
            g.fillRect(0, 0, client.width, client.height);
            break;
        }
        super.paintComponent(g);
    }
    
}